package com.example.a14110100409.yuejiandemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.example.a14110100409.yuejiandemo.R;
import com.example.a14110100409.yuejiandemo.javabean.Club;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by owner on 2017/9/28.
 */

public class ClassInfoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;

    private List mDataList;//数据存储
    private LayoutInflater mLayoutInflater;//准备布局

    public ClassInfoAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_classinfo, parent, false);
        return new ClassInfoAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        final Club.ClubcourseEntity entity = (Club.ClubcourseEntity) mDataList.get(position);

        if (null == entity)
            return;
        ClassInfoAdapter.ViewHolder viewHolder = (ClassInfoAdapter.ViewHolder) holder;
        viewHolder.classTitle.setText(entity.getCourse_name());
        viewHolder.classInfo.setText(entity.getIntroduction());
        viewHolder.classPrice.setText(entity.getCourse_price()+"元");
        viewHolder.classDegree.setRating(Float.parseFloat(entity.getDegree()));
        /*String address="http://172.24.10.175/workout/Uploads/"+entity.getThumb();
        if(!entity.getThumb().equals("")){
            Picasso.with(mContext).load(address).into(viewHolder.coachPhoto);
        }*/
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        RatingBar classDegree;
        TextView classTitle,classInfo,classPrice;

        public ViewHolder(View itemView) {
            super(itemView);
            classTitle = (TextView) itemView.findViewById(R.id.classTitle);
            classInfo = (TextView) itemView.findViewById(R.id.classInfo);
            classPrice = (TextView) itemView.findViewById(R.id.classPrice);
            classDegree = (RatingBar) itemView.findViewById(R.id.classDegree);
        }
    }
}
